﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Newtonsoft.Json;
using RestSharp;
using RestSharp.Deserializers;

namespace WOWA.Utility
{
	public static class ServiceUtility
	{
		public static void Invoke<T>(string baseUrl, string resource, Action<T> callback)
			where T : new()
		{
			RestClient client = new RestClient(baseUrl);
			client.AddHandler("application/json;charset=utf-8", new JsonDeserializer());

			RestRequest quest = new RestRequest(resource, Method.GET);
			quest.RequestFormat = DataFormat.Json;

			client.ExecuteAsync<T>(quest, (response) =>
				{
					var data = response.Data;

					callback(data);
				});
		}
	}
}
